# make时若提示这个文件出错，一般是两种情况：
#	1)文件格式是否是UTF-8 
#	2)TAB是否是8个空格，因为Linux下的Tab是8个空格

MAKEFLAGS = -sR
MKDIR = mkdir
RMDIR = rmdir
CP = cp
CD = cd
DD = dd
RM = rm

ASM		= nasm
CC		= gcc
LD		= ld
OBJCOPY		= objcopy

ASMBFLAGS	= -f elf -w-orphan-labels

# CFLAGS	= -c -Os -std=c99 -m32 -Wall -Wshadow -W -Wconversion -Wno-sign-conversion  -fno-stack-protector -fomit-frame-pointer -fno-builtin -fno-common  -ffreestanding  -Wno-unused-parameter -Wunused-variable

CFLAGS	 	+= -c -Os -std=c99 -m32 
CFLAGS     	+= -Wall -Wshadow -W -Wconversion -Wno-sign-conversion 
CFLAGS     	+= -fno-stack-protector -fomit-frame-pointer -fno-builtin -fno-common  -ffreestanding  
CFLAGS     	+= -Wno-unused-parameter -Wunused-variable

LDFLAGS		= -s -static -T hello.lds -n -Map HelloOS.map 
OJCYFLAGS	= -S -O binary

HELLOOS_OBJS 	:=
HELLOOS_OBJS 	+= entry.o main.o vgastr.o
HELLOOS_ELF 	= HelloOS.elf
HELLOOS_BIN 	= HelloOS.bin

.PHONY : build clean all link bin

all: clean build link bin

clean:	
	$(RM) -rf    *.o   *.bin     *.elf

build: $(HELLOOS_OBJS)

link: $(HELLOOS_ELF)
$(HELLOOS_ELF): $(HELLOOS_OBJS)
	$(LD) $(LDFLAGS) -o $@ $(HELLOOS_OBJS)
bin: $(HELLOOS_BIN)
$(HELLOOS_BIN): $(HELLOOS_ELF)
	$(OBJCOPY) $(OJCYFLAGS) $< $@

%.o : %.asm
	$(ASM) $(ASMBFLAGS) -o $@ $<
%.o : %.c
	$(CC) $(CFLAGS) -o $@ $<


